package per.zqx.rabbit.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitConfig,队列绑定最好是在消费者服务上，因为消费者与队列直接绑定
 *
 *
 * @author Sa, Zhang 2021-06-06 14:56
 */
@Configuration
public class RabbitDirectConfig {
    // 声明交换机，类型是DirectExchange
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct_order_exchange", true, false);
    }

    // 声明SMS、EMAIL、duanxin队列
    @Bean
    public Queue directSmsQueue() {
        return new Queue("sms.direct.queue", true, false, false);
    }

    @Bean
    public Queue directEmailQueue() {
        return new Queue("email.direct.queue", true, false, false);
    }

    @Bean
    public Queue directDuanxinQueue() {
        return new Queue("duanxin.direct.queue", true, false, false);
    }

    // 队列绑定交换机
    @Bean
    public Binding directSmsBinding() {
        return BindingBuilder.bind(directSmsQueue()).to(directExchange()).with("sms");
    }

    @Bean
    public Binding directEmailBinding() {
        return BindingBuilder.bind(directEmailQueue()).to(directExchange()).with("email");
    }

    @Bean
    public Binding directDuanxinBinding() {
        return BindingBuilder.bind(directDuanxinQueue()).to(directExchange()).with("duanxin");
    }

}
